/**
 @file sys_usw_stats.h

 @date 2009-12-15

 @version v2.0

*/
#ifndef _SYS_USW_STATS_H
#define _SYS_USW_STATS_H
#ifdef __cplusplus
extern "C" {
#endif
/***************************************************************
 *
 * Header Files
 *
 ***************************************************************/
#include "ctc_const.h"
#include "ctc_macro.h"
#include "ctc_stats.h"
#include "ctc_linklist.h"
#include "ctc_hash.h"
#include "ctc_vector.h"
#include "sys_usw_chip.h"
#include "sys_usw_stats_api.h"
#include "sys_usw_api.h"

/***************************************************************
 *
 *  common
 *
 ***************************************************************/

#define SYS_STATS_DBG_OUT(level, FMT, ...)                              \
    do {                                                                       \
        CTC_DEBUG_OUT(stats, stats, STATS_SYS, level, FMT, ##__VA_ARGS__);  \
    } while (0)

#define SYS_STATS_DBG_DUMP(FMT, ...)                              \
    do {                                                                       \
        SYS_STATS_DBG_OUT(CTC_DEBUG_LEVEL_DUMP, FMT, ##__VA_ARGS__); \
    } while (0)

#define SYS_STATS_DBG_INFO(FMT, ...)                              \
    do {                                                                       \
        SYS_STATS_DBG_OUT(CTC_DEBUG_LEVEL_INFO, FMT, ##__VA_ARGS__); \
    } while (0)

#define SYS_STATS_DBG_ERROR(FMT, ...)                              \
    do {                                                                       \
        SYS_STATS_DBG_OUT(CTC_DEBUG_LEVEL_ERROR, FMT, ##__VA_ARGS__); \
    } while (0)

#define SYS_STATS_DBG_FUNC() \
    do {                                                                       \
        SYS_STATS_DBG_OUT(CTC_DEBUG_LEVEL_FUNC, "%s()\n",__FUNCTION__);  \
    } while (0)

/***************************************************************
 *
 *  flow stats
 *
 ***************************************************************/

#define SYS_STATS_CHACHE_UPDATE_BYTE_THRESHOLD      32768
#define SYS_STATS_CHACHE_UPDATE_PKT_THRESHOLD       10
#define SYS_STATS_DEFAULT_FIFO_DEPTH_THRESHOLD      15
#define SYS_STATS_DEFAULT_BYTE_THRESHOLD_LO         0x1ff
#define SYS_STATS_DEFAULT_PACKET_THRESHOLD_LO       0x1ff
#define SYS_STATS_DEFAULT_BYTE_THRESHOLD_HI         0x2ff
#define SYS_STATS_DEFAULT_PACKET_THRESHOLD_HI       0x2ff
#define SYS_STATS_DEFAULT_FIFO_DEPTH                0xF

#define SYS_STATS_XQMAC_RAM_MAX               18u
#define SYS_STATS_MAX_MEM_BLOCK                     SYS_STATS_RAM_AT_NUM
#define SYS_STATS_PTR_VEC_SIZE                    256

#define SYS_STATS_PTR_FLAG_HAVE_STATSID             0x00000001
#define SYS_STATS_PTR_FLAG_CREATE_ON_INIT           0x00000002

/* TM queue stats statsptr num is 12288, this is max ram statsptr num of multi chip*/
#define SYS_STATS_PER_RAM_MAX_STATSPTR 12288

/*for AT*/
#define SYS_QOS_QUEUE_STATS_PTR_SHIFT_UC 16
#define SYS_QOS_QUEUE_STATS_PTR_SHIFT_MC 17
#define SYS_QOS_QUEUE_STATS_PTR_SHIFT_DMA 18
#define SYS_QOS_QUEUE_STATS_PTR_SHIFT_PORTTC 19

#define SYS_QUEUE_STATS_DEQ_PKT_SHIFT         0
#define SYS_QUEUE_STATS_DROP_PKT_SHIFT        1
#define SYS_QUEUE_STATS_PTR_PKT_TYPE_SHIFT    14

/* TM DT2 */
enum sys_stats_ram_type_e
{
    SYS_STATS_RAM_EPE_PRIVATE0,
    SYS_STATS_RAM_IPE_PRIVATE0,
    SYS_STATS_RAM_IPE_PRIVATE1,
    SYS_STATS_RAM_IPE_PRIVATE2,
    SYS_STATS_RAM_IPE_PRIVATE3,
    SYS_STATS_RAM_EPE_GLOBAL0,
    SYS_STATS_RAM_EPE_GLOBAL1,
    SYS_STATS_RAM_EPE_GLOBAL2,
    SYS_STATS_RAM_EPE_GLOBAL3,
    SYS_STATS_RAM_IPE_GLOBAL0,
    SYS_STATS_RAM_IPE_GLOBAL1,
    SYS_STATS_RAM_IPE_GLOBAL2,
    SYS_STATS_RAM_IPE_GLOBAL3,

    SYS_STATS_RAM_QUEUE,

    SYS_STATS_RAM_SDC,
    SYS_STATS_RAM_NUM_D2_TM,
    SYS_STATS_RAM_MAX = SYS_STATS_RAM_NUM_D2_TM
};
typedef enum sys_stats_ram_type_e sys_stats_ram_type_t;

/*TMM*/
enum sys_stats_ram_e
{
    SYS_STATS_RAM_EPE_ACL0,
    SYS_STATS_RAM_EPE_ACL1,
    SYS_STATS_RAM_EPE_ACL2,
    SYS_STATS_RAM_EPE_ACL3,

    SYS_STATS_RAM_IPE_ACL0,
    SYS_STATS_RAM_IPE_ACL1,
    SYS_STATS_RAM_IPE_ACL2,
    SYS_STATS_RAM_IPE_ACL3,
    SYS_STATS_RAM_IPE_ACL4,
    SYS_STATS_RAM_IPE_ACL5,
    SYS_STATS_RAM_IPE_ACL6,
    SYS_STATS_RAM_IPE_ACL7,
    SYS_STATS_RAM_IPE_ACL8,
    SYS_STATS_RAM_IPE_ACL9,
    SYS_STATS_RAM_IPE_ACL10,
    SYS_STATS_RAM_IPE_ACL11,
    SYS_STATS_RAM_IPE_ACL12,
    SYS_STATS_RAM_IPE_ACL13,
    SYS_STATS_RAM_IPE_ACL14,
    SYS_STATS_RAM_IPE_ACL15,

    SYS_STATS_RAM_GLOBAL0,
    SYS_STATS_RAM_GLOBAL1,
    SYS_STATS_RAM_GLOBAL2,
    SYS_STATS_RAM_GLOBAL3,
    SYS_STATS_RAM_GLOBAL4,
    SYS_STATS_RAM_GLOBAL5,
    SYS_STATS_RAM_GLOBAL6,
    SYS_STATS_RAM_GLOBAL7,

    SYS_STATS_RAM_QUE,

    SYS_STATS_RAM_NUM_TMM
};
typedef enum sys_stats_ram_e sys_stats_ram_t;

/*AT*/
enum sys_stats_ram_at_e
{
    SYS_STATS_RAM_AT_EPE_ACL0,
    SYS_STATS_RAM_AT_EPE_ACL1,
    SYS_STATS_RAM_AT_EPE_ACL2,
    SYS_STATS_RAM_AT_EPE_ACL3,
    SYS_STATS_RAM_AT_EPE_ACL4,
    SYS_STATS_RAM_AT_EPE_ACL5,
    SYS_STATS_RAM_AT_EPE_ACL6,
    SYS_STATS_RAM_AT_EPE_ACL7,
    SYS_STATS_RAM_AT_EPE_ACL8,
    SYS_STATS_RAM_AT_EPE_ACL9,
    SYS_STATS_RAM_AT_EPE_ACL10,
    SYS_STATS_RAM_AT_EPE_ACL11,

    SYS_STATS_RAM_AT_IPE_ACL0,
    SYS_STATS_RAM_AT_IPE_ACL1,
    SYS_STATS_RAM_AT_IPE_ACL2,
    SYS_STATS_RAM_AT_IPE_ACL3,
    SYS_STATS_RAM_AT_IPE_ACL4,
    SYS_STATS_RAM_AT_IPE_ACL5,
    SYS_STATS_RAM_AT_IPE_ACL6,
    SYS_STATS_RAM_AT_IPE_ACL7,
    SYS_STATS_RAM_AT_IPE_ACL8,
    SYS_STATS_RAM_AT_IPE_ACL9,
    SYS_STATS_RAM_AT_IPE_ACL10,
    SYS_STATS_RAM_AT_IPE_ACL11,
    SYS_STATS_RAM_AT_IPE_ACL12,
    SYS_STATS_RAM_AT_IPE_ACL13,
    SYS_STATS_RAM_AT_IPE_ACL14,
    SYS_STATS_RAM_AT_IPE_ACL15,
    SYS_STATS_RAM_AT_IPE_ACL16,
    SYS_STATS_RAM_AT_IPE_ACL17,
    SYS_STATS_RAM_AT_IPE_ACL18,
    SYS_STATS_RAM_AT_IPE_ACL19,
    SYS_STATS_RAM_AT_IPE_ACL20,
    SYS_STATS_RAM_AT_IPE_ACL21,
    SYS_STATS_RAM_AT_IPE_ACL22,
    SYS_STATS_RAM_AT_IPE_ACL23,

    SYS_STATS_RAM_AT_GLOBAL0,
    SYS_STATS_RAM_AT_GLOBAL1,
    SYS_STATS_RAM_AT_GLOBAL2,
    SYS_STATS_RAM_AT_GLOBAL3,
    SYS_STATS_RAM_AT_GLOBAL4,
    SYS_STATS_RAM_AT_GLOBAL5,
    SYS_STATS_RAM_AT_GLOBAL6,
    SYS_STATS_RAM_AT_GLOBAL7,
    SYS_STATS_RAM_AT_GLOBAL8,
    SYS_STATS_RAM_AT_GLOBAL9,
    SYS_STATS_RAM_AT_GLOBAL10,
    SYS_STATS_RAM_AT_GLOBAL11,
    SYS_STATS_RAM_AT_GLOBAL12,
    SYS_STATS_RAM_AT_GLOBAL13,
    SYS_STATS_RAM_AT_GLOBAL14,
    SYS_STATS_RAM_AT_GLOBAL15,

    SYS_STATS_RAM_AT_QUE_UC,
    SYS_STATS_RAM_AT_QUE_MC,
    SYS_STATS_RAM_AT_DMA_UC,
    SYS_STATS_RAM_AT_DMA_MC,
    SYS_STATS_RAM_AT_PORTTC_UC,
    SYS_STATS_RAM_AT_PORTTC_MC,

    SYS_STATS_RAM_AT_NUM
};
typedef enum sys_stats_ram_at_e sys_stats_ram_at_t;

enum sys_stats_fifo_sync_e
{
    SYS_STATS_FIFO_SYNC_GLOBAL0,
    SYS_STATS_FIFO_SYNC_GLOBAL1,
    SYS_STATS_FIFO_SYNC_GLOBAL2,
    SYS_STATS_FIFO_SYNC_GLOBAL3,
    SYS_STATS_FIFO_SYNC_GLOBAL4,
    SYS_STATS_FIFO_SYNC_GLOBAL5,
    SYS_STATS_FIFO_SYNC_GLOBAL6,
    SYS_STATS_FIFO_SYNC_GLOBAL7,
    SYS_STATS_FIFO_SYNC_GLOBAL8,
    SYS_STATS_FIFO_SYNC_GLOBAL9,
    SYS_STATS_FIFO_SYNC_GLOBAL10,
    SYS_STATS_FIFO_SYNC_GLOBAL11,
    SYS_STATS_FIFO_SYNC_GLOBAL12,
    SYS_STATS_FIFO_SYNC_GLOBAL13,
    SYS_STATS_FIFO_SYNC_GLOBAL14,
    SYS_STATS_FIFO_SYNC_GLOBAL15,

    SYS_STATS_FIFO_SYNC_IPE_ACL0,
    SYS_STATS_FIFO_SYNC_IPE_ACL1,
    SYS_STATS_FIFO_SYNC_IPE_ACL2,
    SYS_STATS_FIFO_SYNC_IPE_ACL3,
    SYS_STATS_FIFO_SYNC_IPE_ACL4,
    SYS_STATS_FIFO_SYNC_IPE_ACL5,
    SYS_STATS_FIFO_SYNC_IPE_ACL6,
    SYS_STATS_FIFO_SYNC_IPE_ACL7,
    SYS_STATS_FIFO_SYNC_IPE_ACL8,
    SYS_STATS_FIFO_SYNC_IPE_ACL9,
    SYS_STATS_FIFO_SYNC_IPE_ACL10,
    SYS_STATS_FIFO_SYNC_IPE_ACL11,
    SYS_STATS_FIFO_SYNC_IPE_ACL12,
    SYS_STATS_FIFO_SYNC_IPE_ACL13,
    SYS_STATS_FIFO_SYNC_IPE_ACL14,
    SYS_STATS_FIFO_SYNC_IPE_ACL15,
    SYS_STATS_FIFO_SYNC_IPE_ACL16,
    SYS_STATS_FIFO_SYNC_IPE_ACL17,
    SYS_STATS_FIFO_SYNC_IPE_ACL18,
    SYS_STATS_FIFO_SYNC_IPE_ACL19,
    SYS_STATS_FIFO_SYNC_IPE_ACL20,
    SYS_STATS_FIFO_SYNC_IPE_ACL21,
    SYS_STATS_FIFO_SYNC_IPE_ACL22,
    SYS_STATS_FIFO_SYNC_IPE_ACL23,

    SYS_STATS_FIFO_SYNC_EPE_ACL0,
    SYS_STATS_FIFO_SYNC_EPE_ACL1,
    SYS_STATS_FIFO_SYNC_EPE_ACL2,
    SYS_STATS_FIFO_SYNC_EPE_ACL3,
    SYS_STATS_FIFO_SYNC_EPE_ACL4,
    SYS_STATS_FIFO_SYNC_EPE_ACL5,
    SYS_STATS_FIFO_SYNC_EPE_ACL6,
    SYS_STATS_FIFO_SYNC_EPE_ACL7,
    SYS_STATS_FIFO_SYNC_EPE_ACL8,
    SYS_STATS_FIFO_SYNC_EPE_ACL9,
    SYS_STATS_FIFO_SYNC_EPE_ACL10,
    SYS_STATS_FIFO_SYNC_EPE_ACL11,

    SYS_STATS_FIFO_SYNC_NUM

};
typedef enum sys_stats_fifo_sync_e sys_stats_fifo_sync_t;

struct sys_stats_prop_s
{
    uint64 ram_bmp;
    uint32 used_cnt   :16;
    uint32 pp_en      :1;
    uint32 rsv        :15;
    uint16 used_cnt_ram[SYS_STATS_RAM_AT_NUM];
};
typedef struct sys_stats_prop_s sys_stats_prop_t;

struct sys_stats_ram_prop_s
{
    uint32 cache_id;
    uint32 base_field_id;
    uint32 total_cnt      :16;
    uint32 used_cnt       :16;
    uint32 base_ptr;
    uint32 base_idx;
    uint32 acl_priority   :6;
    uint32 pp_en          :1;/*0:global ram; 1:pp ram*/
    uint32 scl_bmp        :4;
    uint32 rsv            :21;
    uint32 stats_bmp[CTC_BOTH_DIRECTION];
};
typedef struct sys_stats_ram_prop_s sys_stats_ram_prop_t;

struct sys_stats_bmp_s
{
    uint64 bmp[CTC_B4W_SIZE(SYS_STATS_PER_RAM_MAX_STATSPTR)];
};
typedef struct sys_stats_bmp_s sys_stats_bmp_t;


struct sys_stats_master_s
{
    sal_mutex_t*        p_stats_mutex;

    uint32              stats_bitmap;
    uint8               stats_mode;
    uint8               clear_read_en;

    uint8               opf_type_flow_stats;
    uint8               opf_type_stats_id;

    sys_stats_bmp_t*    statsptr_bmp;
    ctc_list_pointer_t  flow_stats_list[SYS_STATS_MAX_MEM_BLOCK];
    ctc_hash_t*         flow_stats_id_hash;
    ctc_vector_t*       flow_stats_vec[SYS_STATS_MAX_MEM_BLOCK];

    uint32              alloc_count;
    sys_stats_prop_t    stats_type[CTC_BOTH_DIRECTION][SYS_STATS_TYPE_MAX];
    sys_stats_ram_prop_t*   p_stats_ram;

    uint32              ecmp_base_ptr[2];   /* ecmp and hecmp */
    uint32              port_base_ptr[CTC_BOTH_DIRECTION];
    uint32              fid_base_ptr[CTC_BOTH_DIRECTION];
    uint32              init_entry_cnt;
    uint32              pkt_cnt_threashold;
    uint64              byte_cnt_threashold;
    uint32              max_stats_num;
    uint32              max_ecmp_num :16;
    uint32              hecmp_en   :1;
    uint32              rsv   :15;
};
typedef struct sys_stats_master_s sys_stats_master_t;


/***************************************************************
 *
 *  mac stats
 *
 ***************************************************************/

#define SYS_STATS_MTU_PKT_MIN_LENGTH 1024
#define SYS_STATS_MTU1_PKT_MIN_LENGHT 2048
#define SYS_STATS_MTU2_PKT_MIN_LENGTH 1518
#define SYS_STATS_MTU_PKT_MAX_LENGTH 16383
#define SYS_STATS_XQMAC_PORT_MAX               4u
#define SYS_STATS_MTU1_PKT_DFT_LENGTH       1518u
#define SYS_STATS_MTU2_PKT_DFT_LENGTH       1536u

enum sys_mac_stats_property_e
{
    SYS_MAC_STATS_PROPERTY_CLEAR,
    SYS_MAC_STATS_PROPERTY_HOLD,
    SYS_MAC_STATS_PROPERTY_SATURATE,
    SYS_MAC_STATS_PROPERTY_MTU1,
    SYS_MAC_STATS_PROPERTY_MTU2,
    SYS_MAC_STATS_PROPERTY_PFC,
    SYS_MAC_STATS_PROPERTY_NUM
};
typedef enum sys_mac_stats_property_e sys_mac_stats_property_t;

/**
 @brief  Define mac receive statistics storage structor
*/
struct sys_stats_mac_rec_s
{
    uint64 good_ucast_pkts;
    uint64 good_ucast_bytes;
    uint64 good_mcast_pkts;
    uint64 good_mcast_bytes;
    uint64 good_bcast_pkts;
    uint64 good_bcast_bytes;
    uint64 good_normal_pause_pkts;
    uint64 good_normal_pause_bytes;
    uint64 good_pfc_pause_pkts;
    uint64 good_pfc_pause_bytes;
    uint64 good_control_pkts;
    uint64 good_control_bytes;
    uint64 fcs_error_pkts;
    uint64 fcs_error_bytes;
    uint64 mac_overrun_pkts;
    uint64 mac_overrun_bytes;
    uint64 good_63_pkts;
    uint64 good_63_bytes;
    uint64 bad_63_pkts;
    uint64 bad_63_bytes;
    uint64 good_mtu1_to_mtu2_pkts;
    uint64 good_mtu1_to_mtu2_bytes;
    uint64 bad_mtu1_to_mtu2_pkts;
    uint64 bad_mtu1_to_mtu2_bytes;
    uint64 good_jumbo_pkts;
    uint64 good_jumbo_bytes;
    uint64 bad_jumbo_pkts;
    uint64 bad_jumbo_bytes;
    uint64 pkts_64;
    uint64 bytes_64;
    uint64 pkts_65_to_127;
    uint64 bytes_65_to_127;
    uint64 pkts_128_to_255;
    uint64 bytes_128_to_255;
    uint64 pkts_256_to_511;
    uint64 bytes_256_to_511;
    uint64 pkts_512_to_1023;
    uint64 bytes_512_to_1023;
    uint64 pkts_1024_to_1518;
    uint64 bytes_1024_to_1518;
    uint64 pkts_1518_to_2047;
    uint64 bytes_1518_to_2047;
    uint64 pkts_2047_to_mtu1;
    uint64 bytes_2047_to_mtu1;

};
typedef struct sys_stats_mac_rec_s sys_stats_mac_rec_t;

/**
 @brief  Define mac transmit statistics storage structor
*/
struct sys_stats_mac_snd_s
{
    uint64 good_ucast_pkts;
    uint64 good_ucast_bytes;
    uint64 good_mcast_pkts;
    uint64 good_mcast_bytes;
    uint64 good_bcast_pkts;
    uint64 good_bcast_bytes;
    uint64 good_pause_pkts;
    uint64 good_pause_bytes;
    uint64 good_control_pkts;
    uint64 good_control_bytes;
    uint64 fcs_error_pkts;
    uint64 fcs_error_bytes;
    uint64 mac_underrun_pkts;
    uint64 mac_underrun_bytes;
    uint64 pkts_63;
    uint64 bytes_63;
    uint64 pkts_64;
    uint64 bytes_64;
    uint64 pkts_65_to_127;
    uint64 bytes_65_to_127;
    uint64 pkts_128_to_255;
    uint64 bytes_128_to_255;
    uint64 pkts_256_to_511;
    uint64 bytes_256_to_511;
    uint64 pkts_512_to_1023;
    uint64 bytes_512_to_1023;
    uint64 pkts_1024_to_1518;
    uint64 bytes_1024_to_1518;
    uint64 pkts_1519_to_2047;
    uint64 bytes_1519_to_2047;
    uint64 pkts_2047_to_mtu1;
    uint64 bytes_2047_to_mtu1;
    uint64 pkts_mtu1_to_mtu2;
    uint64 bytes_mtu1_to_mtu2;
    uint64 jumbo_pkts;
    uint64 jumbo_bytes;

};
typedef struct sys_stats_mac_snd_s sys_stats_mac_snd_t;

/* the value defined should be consistent with ctc_stats.h */
enum sys_stats_map_mac_rx_type_e
{
    SYS_STATS_MAP_MAC_RX_GOOD_UC_PKT = 0,
    SYS_STATS_MAP_MAC_RX_GOOD_UC_BYTE = 1,
    SYS_STATS_MAP_MAC_RX_GOOD_MC_PKT = 2,
    SYS_STATS_MAP_MAC_RX_GOOD_MC_BYTE = 3,
    SYS_STATS_MAP_MAC_RX_GOOD_BC_PKT = 4,
    SYS_STATS_MAP_MAC_RX_GOOD_BC_BYTE = 5,
    SYS_STATS_MAP_MAC_RX_GOOD_NORMAL_PAUSE_PKT = 8,
    SYS_STATS_MAP_MAC_RX_GOOD_NORMAL_PAUSE_BYTE = 9,
    SYS_STATS_MAP_MAC_RX_GOOD_PFC_PAUSE_PKT = 10,
    SYS_STATS_MAP_MAC_RX_GOOD_PFC_PAUSE_BYTE = 11,
    SYS_STATS_MAP_MAC_RX_GOOD_CONTROL_PKT = 12,
    SYS_STATS_MAP_MAC_RX_GOOD_CONTROL_BYTE = 13,
    SYS_STATS_MAP_MAC_RX_FCS_ERROR_PKT = 18,
    SYS_STATS_MAP_MAC_RX_FCS_ERROR_BYTE = 19,
    SYS_STATS_MAP_MAC_RX_MAC_OVERRUN_PKT = 22,
    SYS_STATS_MAP_MAC_RX_MAC_OVERRUN_BYTE = 23,
    SYS_STATS_MAP_MAC_RX_GOOD_63B_PKT = 30,
    SYS_STATS_MAP_MAC_RX_GOOD_63B_BYTE = 31,
    SYS_STATS_MAP_MAC_RX_BAD_63B_PKT = 32,
    SYS_STATS_MAP_MAC_RX_BAD_63B_BYTE = 33,
    SYS_STATS_MAP_MAC_RX_GOOD_1519B_PKT = 34,
    SYS_STATS_MAP_MAC_RX_GOOD_1519B_BYTE = 35,
    SYS_STATS_MAP_MAC_RX_BAD_1519B_PKT = 36,
    SYS_STATS_MAP_MAC_RX_BAD_1519B_BYTE = 37,
    SYS_STATS_MAP_MAC_RX_GOOD_JUMBO_PKT = 38,
    SYS_STATS_MAP_MAC_RX_GOOD_JUMBO_BYTE = 39,
    SYS_STATS_MAP_MAC_RX_BAD_JUMBO_PKT = 40,
    SYS_STATS_MAP_MAC_RX_BAD_JUMBO_BYTE = 41,
    SYS_STATS_MAP_MAC_RX_64B_PKT = 42,
    SYS_STATS_MAP_MAC_RX_64B_BYTE = 43,
    SYS_STATS_MAP_MAC_RX_127B_PKT = 44,
    SYS_STATS_MAP_MAC_RX_127B_BYTE = 45,
    SYS_STATS_MAP_MAC_RX_255B_PKT = 46,
    SYS_STATS_MAP_MAC_RX_255B_BYTE = 47,
    SYS_STATS_MAP_MAC_RX_511B_PKT = 48,
    SYS_STATS_MAP_MAC_RX_511B_BYTE = 49,
    SYS_STATS_MAP_MAC_RX_1023B_PKT = 50,
    SYS_STATS_MAP_MAC_RX_1023B_BYTE = 51,
    SYS_STATS_MAP_MAC_RX_1518B_PKT = 52,
    SYS_STATS_MAP_MAC_RX_1518B_BYTE = 53,
    SYS_STATS_MAP_MAC_RX_2047B_PKT = 54,
    SYS_STATS_MAP_MAC_RX_2047B_BYTE = 55,
    SYS_STATS_MAP_MAC_RX_MTU1_PKT = 56,
    SYS_STATS_MAP_MAC_RX_MTU1_BYTE = 57,

    SYS_STATS_MAP_MAC_RX_TYPE_NUM
};
typedef enum sys_stats_map_mac_rx_type_e sys_stats_map_mac_rx_type_t;

/* the value defined should be consistent with ctc_stats.h */
enum sys_stats_map_mac_tx_type_e
{
    SYS_STATS_MAP_MAC_TX_GOOD_UC_PKT = 0,
    SYS_STATS_MAP_MAC_TX_GOOD_UC_BYTE = 1,
    SYS_STATS_MAP_MAC_TX_GOOD_MC_PKT = 2,
    SYS_STATS_MAP_MAC_TX_GOOD_MC_BYTE = 3,
    SYS_STATS_MAP_MAC_TX_GOOD_BC_PKT = 4,
    SYS_STATS_MAP_MAC_TX_GOOD_BC_BYTE = 5,
    SYS_STATS_MAP_MAC_TX_GOOD_PAUSE_PKT = 6,
    SYS_STATS_MAP_MAC_TX_GOOD_PAUSE_BYTE = 7,
    SYS_STATS_MAP_MAC_TX_GOOD_CONTROL_PKT = 8,
    SYS_STATS_MAP_MAC_TX_GOOD_CONTROL_BYTE = 9,
    SYS_STATS_MAP_MAC_TX_FCS_ERROR_PKT = 32,
    SYS_STATS_MAP_MAC_TX_FCS_ERROR_BYTE = 33,
    SYS_STATS_MAP_MAC_TX_MAC_UNDERRUN_PKT = 30,
    SYS_STATS_MAP_MAC_TX_MAC_UNDERRUN_BYTE = 31,
    SYS_STATS_MAP_MAC_TX_63B_PKT = 12,
    SYS_STATS_MAP_MAC_TX_63B_BYTE = 13,
    SYS_STATS_MAP_MAC_TX_64B_PKT = 14,
    SYS_STATS_MAP_MAC_TX_64B_BYTE = 15,
    SYS_STATS_MAP_MAC_TX_127B_PKT = 16,
    SYS_STATS_MAP_MAC_TX_127B_BYTE = 17,
    SYS_STATS_MAP_MAC_TX_225B_PKT = 18,
    SYS_STATS_MAP_MAC_TX_225B_BYTE = 19,
    SYS_STATS_MAP_MAC_TX_511B_PKT = 20,
    SYS_STATS_MAP_MAC_TX_511B_BYTE = 21,
    SYS_STATS_MAP_MAC_TX_1023B_PKT = 22,
    SYS_STATS_MAP_MAC_TX_1023B_BYTE = 23,
    SYS_STATS_MAP_MAC_TX_1518B_PKT = 24,
    SYS_STATS_MAP_MAC_TX_1518B_BYTE = 25,

    SYS_STATS_MAP_MAC_TX_2047B_PKT = 34 ,
    SYS_STATS_MAP_MAC_TX_2047B_BYTE = 35,

    SYS_STATS_MAP_MAC_TX_MTU1_PKT = 36,
    SYS_STATS_MAP_MAC_TX_MTU1_BYTE = 37,
    SYS_STATS_MAP_MAC_TX_MTU2_PKT = 38,
    SYS_STATS_MAP_MAC_TX_MTU2_BYTE = 39,

    SYS_STATS_MAP_MAC_TX_JUMBO_PKT = 28,
    SYS_STATS_MAP_MAC_TX_JUMBO_BYTE = 29,

    SYS_STATS_MAP_MAC_TX_TYPE_NUM
};
typedef enum sys_stats_map_mac_tx_type_e sys_stats_map_mac_tx_type_t;

enum sys_stats_mac_cnt_type_e
{
    SYS_STATS_MAC_CNT_TYPE_PKT,
    SYS_STATS_MAC_CNT_TYPE_BYTE,
    SYS_STATS_MAC_CNT_TYPE_NUM
};
typedef enum sys_stats_mac_cnt_type_e sys_stats_mac_cnt_type_t;

enum sys_mac_stats_store_mode_e
{
     SYS_MAC_STATS_STORE_HW,
     SYS_MAC_STATS_STORE_SW
};
typedef enum sys_mac_stats_store_mode_e sys_mac_stats_store_mode_t;

struct sys_mac_stats_rx_s
{
    uint64 mac_stats_rx_bytes[SYS_STATS_MAC_RCV_NUM];
    uint64 mac_stats_rx_pkts[SYS_STATS_MAC_RCV_NUM];
};
typedef  struct sys_mac_stats_rx_s sys_mac_stats_rx_t;

struct sys_mac_stats_tx_s
{
    uint64 mac_stats_tx_bytes[SYS_STATS_MAC_SEND_NUM];
    uint64 mac_stats_tx_pkts[SYS_STATS_MAC_SEND_NUM];
};
typedef struct sys_mac_stats_tx_s sys_mac_stats_tx_t;

struct sys_qmac_stats_s
{
    sys_mac_stats_rx_t mac_stats_rx[SYS_STATS_XQMAC_PORT_MAX];
    sys_mac_stats_tx_t mac_stats_tx[SYS_STATS_XQMAC_PORT_MAX];
};
typedef struct sys_qmac_stats_s sys_qmac_stats_t;

struct sys_qmac_pfc_stats_s
{
    uint64 mac_stats_rx[8];
    uint64 mac_stats_tx[8];
};
typedef struct sys_qmac_pfc_stats_s sys_qmac_pfc_stats_t;


struct sys_stats_mac_throughput_s
{
    uint64 bytes[SYS_USW_MAX_PORT_NUM][CTC_STATS_MAC_STATS_MAX];
    sal_systime_t timestamp[SYS_USW_MAX_PORT_NUM];
};
typedef struct sys_stats_mac_throughput_s sys_stats_mac_throughput_t;
typedef int32 (*sys_usw_mac_stats_sync_cb)(uint8, uint32*, uint32*);

struct sys_mac_stats_master_s
{
    sal_mutex_t* p_stats_mutex;

    uint8    stats_mode;
    uint8    query_mode;
    uint8    store_mode;
    uint8    rsv;
    uint32   mac_timer;
    sys_qmac_stats_t*    qmac_stats_table;
    sys_qmac_pfc_stats_t* qmgc_pfc_stats_table;
    sys_qmac_stats_t     cpumac_stats[SYS_USW_CPU_MAC_NUM];
    sys_usw_mac_stats_sync_cb sync_cb;
    sys_stats_mac_throughput_t mac_throughput;
};
typedef struct sys_mac_stats_master_s sys_mac_stats_master_t;

#ifdef __cplusplus
}
#endif

#endif

